/**
 * Created by SXX on 2018/3/31
 */

import java.io.*;
import java.util.Scanner;

public class shiyan1 {
    public static void main(String[] args)  {
        EncryptAndDecrypt person = new EncryptAndDecrypt();
        System.out.print("请选择加密还是解密：（加密输入1，解密输入2）");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n == 1) {
            System.out.print("请输入明文：");
            Scanner scanner1 = new Scanner(System.in);
            String m = scanner1.nextLine();
            System.out.print("请输入密钥:");
            Scanner scanner2 = new Scanner(System.in);
            int k = scanner2.nextInt();
            try {
                String serct = person.encrypt(m, k);
                System.out.println("密文是：" + serct);
            }
            catch (EadException e){
                System.out.println(e.warnMess());
            }
        } else {
            System.out.print("请输入密文：");
            Scanner scanner1 = new Scanner(System.in);
            String m = scanner1.nextLine();
            System.out.print("请输入密钥:");
            Scanner scanner2 = new Scanner(System.in);
            int k = scanner2.nextInt();
            try {
                String source = person.decrypt(m, k);
                System.out.print("明文是：" + source);
            }
            catch (EadException e){
                System.out.println(e.warnMess());
            }
        }
    }
}

